Skip to content

Job Traceability, Management, and Audibility Overhaul#645

Open
bencap wants to merge 84 commits intorelease-2026.2.0from
feature/bencap/627/job-traceability
Open

Job Traceability, Management, and Audibility Overhaul#645
bencap wants to merge 84 commits intorelease-2026.2.0from
feature/bencap/627/job-traceability

Conversation

@bencap
Copy link
Copy Markdown
Collaborator

@bencap bencap commented Jan 29, 2026

This PR introduces a robust, auditable, and maintainable background job system for MaveDB, supporting both standalone jobs and complex pipelines. It provides a strong foundation for future workflow automation, error recovery, and developer onboarding.

Features include:

1. Worker Job System Refactor & Enhancements
Refactored the monolithic worker job system into a modular architecture:

  • Split jobs into domain-specific modules: data_management, external_services, variant_processing, etc ( a94c2fb, new files in jobs).
  • Centralized job registration in registry.py for ARQ worker configuration (a94c2fb, 0416b2d).
  • Added standalone job definitions and improved lifecycle context for job submission (0416b2d, 60ef67d).
  • Integrated PipelineFactory for variant creation and update processes. (See: 987b38a)

2. Job & Pipeline Management Infrastructure
Implemented JobManager and PipelineManager classes for robust job and pipeline lifecycle management: (05fc52b, ae18eeb, 3799d84, 1e447a7, 7b44346)

  • Atomic state transitions, progress tracking, retry logic, and error handling.
  • Pipeline coordination, dependency management, pausing/unpausing, and cancellation.
  • Custom exception hierarchies for clear error recovery.
  • Added context manager for database session management and streamlined context handling in decorators (3ca697a, c61bd41, 010f15c).

3. Decorator System for Jobs and Pipelines
Introduced decorators for job and pipeline management:
(c2100a2, 155e549, 4a4055d, 3c4e6b9, 010f15c)

  • with_job_management: Automatic job lifecycle management, error handling, and progress tracking.
  • with_pipeline_management: Pipeline coordination after job completion.
  • with_guaranteed_job_run_record: Ensures audit trail by persisting a JobRun record before execution.
    Improved test mode support and simplified stacking/usage patterns.

4. Comprehensive Test Suite
Added and refactored unit and integration tests for all job modules, managers, and decorators.
(05fc52b, ae18eeb, a701d53, 806f8ed, 011522c, 010f15c, 8a22306, a716cc9, b0397b4, 8c5e225, 3c4e6b9, 4a4055d, 1fe076a, 1abe4c6)
Enhanced test coverage for error handling, state transitions, and job orchestration.
Introduced fixtures and utilities for easier test setup and mocking.
Categorized tests with markers for unit, integration, and network tests.
(16a5a50, f34939c)

5. Developer Documentation
Added detailed markdown documentation in the worker/jobs/] directory:
(1abe4c6)

  • System overview, decorator usage, manager responsibilities, pipeline management, job registry/configuration, and best practices.
  • Entry-point README and table of contents for easy navigation.
  • Guidance on error handling, job design, and testing strategies.

6. Database & Model Changes

  • Added new tables and enums for job traceability JobRun, Pipeline, JobDependency, etc.
    (1db6b68)
    Alembic migration for pipeline and job tracking schema.
    Updated models and enums to support new job/pipeline features.

7. Miscellaneous Improvements
Dependency updates (e.g., added asyncclick).
(a3f36d1)

  • Logging and error reporting enhancements.
  • Cleaned up legacy code, removed obsolete files, and improved code organization.

@bencap bencap force-pushed the feature/bencap/627/job-traceability branch 6 times, most recently from da26721 to f3ea5ce Compare February 4, 2026 23:08
Base automatically changed from feature/bencap/derived-gene-name-from-mapped-output to release-2025.6.0 February 4, 2026 23:58
Base automatically changed from release-2025.6.0 to main February 6, 2026 19:08
@bencap bencap force-pushed the feature/bencap/627/job-traceability branch 2 times, most recently from 1aa5409 to 1fb9fdd Compare February 17, 2026 19:40
@bencap bencap changed the base branch from main to release-2026.2.0 February 17, 2026 23:28
@bencap bencap marked this pull request as ready for review February 17, 2026 23:31
@bencap bencap linked an issue Feb 24, 2026 that may be closed by this pull request
bencap added 15 commits April 15, 2026 17:09
…cture

Break down 1767-line jobs.py into domain-driven modules, improving
maintainability and developer experience.

- variant_processing/: Variant creation and VRS mapping
- external_services/: ClinGen, UniProt, gnomAD integrations
- data_management/: Database and view operations
- utils/: Shared utilities (state, retry, constants)
- registry.py: Centralized ARQ job configuration

- constants.py: Environment configuration
- redis.py: Redis connection settings
- lifecycle.py: Worker lifecycle hooks
- worker.py: Main ArqWorkerSettings class

- All job functions maintain identical behavior
- Registry provides BACKGROUND_FUNCTIONS/BACKGROUND_CRONJOBS lists for ARQ initialization
- Test structure mirrors source organization

This refactor ensures ARQ worker initialization is backwards compatible.

The modular architecture establishes a more maintainable foundation for MaveDB's automated processing workflows while preserving all existing functionality.
Implement complete database foundation for pipeline-based job tracking and monitoring:

Database Tables:
• pipelines - High-level workflow grouping with correlation IDs for end-to-end tracing
• job_runs - Individual job execution tracking with full lifecycle management
• job_dependencies - Workflow orchestration with success/completion dependency types
• job_metrics - Detailed performance metrics (CPU, memory, execution time, business metrics)
• variant_annotation_status - Granular variant-level annotation tracking with success data

Key Features:
• Pipeline workflow management with dependency resolution
• Comprehensive job lifecycle tracking (pending → running → completed/failed)
• Retry logic with configurable limits and backoff strategies
• Resource usage and performance metrics collection
• Variant-level annotation status for debugging failures
• Correlation ID support for request tracing across system
• JSONB metadata fields for flexible job-specific data
• Optimized indexes for common query patterns

Schema Design:
• Foreign key relationships maintain data integrity
• Check constraints ensure valid enum values and positive numbers
• Strategic indexes optimize dependency resolution and metrics queries
• Cascade deletes prevent orphaned records
• Version tracking for audit and debugging

Models & Enums:
• SQLAlchemy models with proper relationships and hybrid properties
• Comprehensive enum definitions for job/pipeline status and failure categories
Add comprehensive job lifecycle management with status-based completion:

* Implement convenience methods for common job outcomes:
  - succeed_job() for successful completion
  - fail_job() for error handling with exception details
  - cancel_job() for user/system cancellation
  - skip_job() for conditional job skipping
* Enhance progress tracking with increment_progress() and set_progress_total()
* Add comprehensive error handling with specific exception types
* Improve job state validation and atomic transaction handling
* Implement extensive test coverage for all job operations
- Created PipelineManager capable of coordinating jobs within a pipeline context
- Introduced `construct_bulk_cancellation_result` to standardize cancellation result structures.
- Added `job_dependency_is_met` to check job dependencies based on their types and statuses.
- Created comprehensive tests for PipelineManager covering initialization, job coordination, status transitions, and error handling.
- Implemented mocks for database and Redis dependencies to isolate tests.
- Added tests for job enqueuing, cancellation, pausing, unpausing, and retrying functionalities.
Adds decorators for managed jobs and pipelines. These can be applied to async ARQ functions to automatically persist their state as they execute
bencap added 21 commits April 15, 2026 17:11
…calls

Implements 24-hour Redis cache for ClinGen Allele Registry API responses,
significantly reducing API load when processing multiple ClinVar control
versions that query the same alleles. Converts three ClinGen functions to
async with @cached decorator, implements memory backend for testing, and
handles 404 responses as cacheable "no data" results while raising exceptions
for other API failures. Includes comprehensive test coverage and type stubs
for the untyped aiocache library.

- Add aiocache optional dependency with Redis backend support
- Create cache configuration module with environment-based backend selection
- Convert get_canonical_pa_ids, get_matching_registered_ca_ids, and
  get_associated_clinvar_allele_id to async cached functions
- Return empty string/list for "no data" cases to enable caching of modal outcomes
- Implement 404-specific error handling: cache permanent absences, raise for transient failures
- Add memory cache backend for testing without Redis dependency
- Create type stubs for aiocache.Cache and aiocache.cached decorator
- Add 43 new tests covering caching behavior, configuration, and network interactions
Add periodic cleanup job to detect and recover jobs stuck in QUEUED,
RUNNING, or PENDING states beyond timeout thresholds. Jobs can become
stalled due to worker crashes, race conditions during enqueue, network
issues, or database transaction failures.

Cleanup logic:
- QUEUED jobs stalled >10 min (stuck between state change and ARQ pickup)
- RUNNING jobs stalled >60 min (worker likely crashed mid-execution)
- PENDING jobs stalled >30 min (pipeline coordination failure)

Unified retry handler workflow:
1. Fail job with TIMEOUT category for being stalled
2. Check retry eligibility via should_retry()
3. If eligible: prepare retry and check dependencies
4. For pipeline jobs: validate dependencies before enqueueing
   - Skip if dependencies failed (leave in PENDING for pipeline manager)
   - Wait if dependencies not ready (leave in PENDING)
   - Enqueue if dependencies satisfied
5. If max retries exceeded or enqueue fails: mark SYSTEM_ERROR

Key features:
- Graceful handling of edge cases (missing started_at, max retries)
- Pipeline dependency awareness (avoids enqueueing guaranteed failures)
- Comprehensive test coverage (42 tests: 22 unit, 19 integration, 1 ARQ)

This safety net ensures jobs don't remain in limbo indefinitely and
provides automatic recovery from transient infrastructure failures.
The `hgvs_assay_level` field was not being set during the mapping
job, deferring it for a later job. Derive it from the post-mapped VRS
object at creation time using `get_hgvs_from_post_mapped`.

Adds a test assertion to verify the field is populated after mapping.
@bencap bencap force-pushed the feature/bencap/627/job-traceability branch from 6b55270 to 12ba7e1 Compare April 16, 2026 00:16
@bencap bencap force-pushed the feature/bencap/627/job-traceability branch from bcd123c to bccaff7 Compare April 16, 2026 01:00
bencap added 5 commits April 16, 2026 11:17
The previous behavior always scoped retirement of current annotation
records to the same (variant, type, version) tuple. This is correct
for ClinVar, where records from different source
versions should coexist independently.

For the mapping pipeline, ClinGen and gnomAD,, a new run should supersede all prior
results regardless of which version produced them.

- Add `replace_all_versions: bool = True` parameter to
  `AnnotationStatusManager.add_annotation`; default clobbers all
  versions so existing callers that omit the flag get the broader
  retirement behavior
- Explicitly pass `replace_all_versions=False` on all ClinVar call
  sites to preserve per-version record coexistence
- Add `TestAnnotationStatusManagerReplaceAllVersionsUnit` covering
  both modes across type, variant, and version isolation boundaries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize Clinvar Control Refresh Job Traceability and Auditing for Variant-level Job Results Consider Retaining Score and Count Raw Files

1 participant